<template>
  <div>
    <van-nav-bar
      title="个人中心"
      right-text="退出"
      @click-right="loginOut"
    />
    <div class="user">
      <div><img src="../../assets/logo.png" alt="" srcset=""></div>
      <div class="user-name">{{userInfo.username}}</div>
      <div>类型：{{userInfo.type == 1 ? '老板' : '消费者'}}</div>
    </div>
  </div>
</template>
<script>
import {reqUsers} from '@/api/index'
import {clearAllCookie, addCookie} from '@/utils/index'
export default {
  data () {
    return {
      userInfo:{}
    }
  },
  mounted() {
    this.getUsers()
  },
  methods:{
    async getUsers () {
      const res = await reqUsers()
      if(res.status ===200) {
        this.userInfo = res.data
        addCookie('type',res.data.type,30)
      }else{
        this.$toast(res.msg)
        this.loginOut()
      }
    },
    loginOut () {
      clearAllCookie()
      this.$router.go(0)
    }
  }
}
</script>
<style lang='less' scoped>
.user{
  margin: 15px 0 0 0;
  padding: 10px;
  background-color: #f7f7f7;
  text-align: center;
  img{
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .user-name{
    padding: 5px 0 8px 0;
    font-size: 24px;
    color: #333333;
    font-weight: 500;
  }
}
</style>